<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB,Session,View;

class FaqController extends CommonController
{
    public function __init()
    {
        $menu = DB::table('faq_category')->get();
        foreach ($menu as $m){
            $m->faqs = DB::table('faq')->where('pid', $m->id)->get();
        }
        
        View::share('faqMenu', $menu);
    }
    
    public function index($id=0)
    {
        if($id == 0){
            // 查询第一个
            $data = DB::table('faq')->first();
        } else {
            $data = DB::table('faq')->find($id);
        }
        
        return view('home.faq.index', compact('data'));
    }
}
